<%@ page import="bean.PollUser, java.sql.*, connection.*, java.util.*" %>
<jsp:useBean id="user" class="bean.PollUser" scope="request" />
<jsp:setProperty name="user" property="*"/>

<%
/*
PollCreator will want quick access to polls they have created
*/
Connection conn = new DbConnection().getConn();

String username = user.getUsername();
System.out.println(username);
String sql= "SELECT Poll.ID, Poll.Name, Poll.Description, Poll.Version FROM Poll WHERE Poll.Creatorname = '"+username+"'";
System.out.println(sql);
PreparedStatement ps = conn.prepareStatement(sql);
ArrayList<String[]> polls = new ArrayList<String[]>();
boolean hasPolls = false;
try{
	ResultSet rs = ps.executeQuery();
	while(rs.next()){
		hasPolls = true;
		String temp[] = {"", "", "" , ""};
		temp[0] = rs.getString("ID");
		temp[1] = rs.getString("NAME");
		temp[2] = rs.getString("DESCRIPTION");
		temp[3] = rs.getString("VERSION");
		polls.add(temp);
		//temp[3] is reserved for status
	}
}catch(SQLException e){
	System.out.print(e.toString());
}
%>
<div class="entrytitle">
Poll Creation
	<div class="entry">
	Polls you have created:<br/><br/>
	<div class="tableborder"><table class="blockTable">
			<thead>
			<tr>
				<td>Name</td>
				<td>Description</td>
				<td></td>
			</tr>
			</thead>
			<tbody>
			<tr>
			<td><a href="setupPollCreate.jsp?newPoll=true"><input type="submit" value="+ Create new poll" class="button" /></a></td>
			<td></td><td></td>
			</tr>
		<%
		if(hasPolls){
			for(String[] curr : polls){%>
				<tr>
					<td>
						<%
						out.write(curr[1]);
					%></td><td><%
						out.write(curr[2]);
						%>
					</td>
					<td>
						<a href="setupQuestionCreate.jsp?pid=<%=curr[0]%>&ver=<%=curr[3]%>&des=<%=curr[2] %>&name=<%=curr[1]%>">
							<input type="submit" value="Edit" class="button" style="display:inline"/>
						</a>
						<a href="setupQuestionCreate.jsp?assign=true&pid=<%=curr[0]%>&ver=<%=curr[3]%>&name=<%=curr[1]%>">
							<input type="submit" value="Assign Master" class="button" style="display:inline"/>
						</a>
					</td>
				</tr>
				<%
			}
		}
		%>
		</tbody>
				</table></div>
	</div>
</div>